package com.itheima.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.config.StudentConfig;
import com.itheima.pojo.Result;
import jakarta.annotation.Resource;

import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;


@RestController
@RequestMapping("/yml")
public class TestReadYmlController {
//    //@Value只能读8个基本数据类型以及数组类型
//    @Value("${student.name}")
//    String name;
//    @Value("${student.age}")
//    Integer age;
//    @Value("${student.subject}")
//    String[] subject;
//    @Value("${student.teachers}")
    @Resource
    StudentConfig config;

    @Resource
    Environment env;

    @GetMapping
    public Result readCustomConfigByYml(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name",config.getName());
        jsonObject.put("age",config.getAge());
        jsonObject.put("subject",config.getSubject());
        jsonObject.put("teachers",config.getTeachers());
        jsonObject.put("family",config.getFamily());
        String property = env.getProperty("server.port");
        jsonObject.put("port",property);
        return Result.success(jsonObject);
    }
}
